https://leetcode.cn/problems/number-of-visible-people-in-a-queue/submissions/670790582/

class Solution {
public:
	vector<int> canSeePersonsCount(vector<int>& heights) {
		int n=heights.size();
		vector<int> stack;
		vector<int> res(n,0);
		for(int i=n-1;i>=0;i--){
			int h=heights[i];
			while(!stack.empty()&&stack.back()<h){
				res[i]++;
				stack.pop_back();
			}
			if(!stack.empty()) res[i]++;
			stack.push_back(h);
		}
		return res;
	}
};
